package bb.lanxing.lib.devices.core.scanner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MultiProtocolDeviceScanner implements DeviceScanner {
    private final List<DeviceScanner> deviceScanners;

    public MultiProtocolDeviceScanner(DeviceScanner... deviceScannerArr) {
        ArrayList arrayList = new ArrayList();
        this.deviceScanners = arrayList;
        if (deviceScannerArr != null) {
            arrayList.addAll(Arrays.asList(deviceScannerArr));
        }
    }

    @Override
    public boolean startScan() {
        return startScan(-1L);
    }

    @Override
    public boolean startScan(long j) {
        boolean z = false;
        for (DeviceScanner deviceScanner : this.deviceScanners) {
            z |= deviceScanner.startScan(j);
        }
        return z;
    }

    @Override
    public boolean isScanning() {
        for (DeviceScanner deviceScanner : this.deviceScanners) {
            if (deviceScanner.isScanning()) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean stopScan() {
        for (DeviceScanner deviceScanner : this.deviceScanners) {
            deviceScanner.stopScan();
        }
        return true;
    }

    @Override
    public void release() {
        for (DeviceScanner deviceScanner : this.deviceScanners) {
            deviceScanner.release();
        }
    }
}
